<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../../layout/top.jsp" %>
<div class="main">
	<div class="m_con" id="table_con">
		<div class="m_tit clearfix"><b class="f18">${config.beanDescription}信息</b><span class="mt_action"><button id="addBtn" class="a_btn"><i class="icon30 add_icon"></i>添加</button></span></div>
		<form id="searchForm">
			<table class="c_table m_t20">
				<tr>
					<td class="t_r">条件：</td>
					<td>
						<input class="all_txt"  name="" type="text">
					</td>
				</tr>
			</table>
		</form>
		<div class="action_b"><button id="searchbtn" class="b_btn"><i class="icon30 search_icon"></i>查询</button></div>
		<table class="table_list m_t30" id="searchcon">

		</table>
		<div class="page" id="tbpager">

		</div>
		<script type="text/html" id="tb_template">
			<thead>
				<tr>
<#list columnList as column>				
					<th>${column.dbColumnComment}</th>
</#list>
					<th>操作</th>					
				</tr>
		</thead>
		<tbody>
			<!if(list.length>0) { !>
				<!for(var i=0,len=list.length;i<len;i++){
					var item = list[i];
				!>
				<tr>
					<#list columnList as column>				
						<td title="<!=item["${column.javaPropertyName}"]!>"><!=item["${column.javaPropertyName}"]!></td>
					</#list>						
						<td>
							<a title="编辑" class="icon25 edit_icon m_r5" action="edit" data-id="<!=item["id"]!>"></a>
							<a title="删除" class="icon25 del_icon m_r5"  action="delete" data-id="<!=item["id"]!>"></a>
						</td>
				</tr>
			<!}!>
			<!}else{!>
				<tr>
					<td colspan="${columnList?size}"> 暂无数据</td>
				</tr>
			<!}!>
		</tbody>
		</script>
	</div>
	<div class="m_con" id="detail_con" style="display: none;">
	
	</div>
	<script type="text/html" id="detail_add_template">
		<div class="m_tit clearfix"><b class="f18">添加${config.beanDescription}</b></div>
		<form action="${ctx}/${simpleBeanName}/add.do" method="post" id="addform" enctype="multipart/form-data" >

		<div class="clearfix p_t20">
			<div class="u_info">
				<table class="u_table">
						<#list columnList as column>				
						<tr>
							<td class="t_r">${column.dbColumnComment}：</td>
							<td><input type="text" class="all_txt" id="${column.javaPropertyName}" name="${column.javaPropertyName}" /></td>
						</tr>					
						</#list>						
				</table>
			</div>
		</div>
		
		</form>
		<div class="action_b">
			<button class="b_btn m_r20" id="enterbtn">确定</button>
			<button class="b_btn" id="backbtn">返回</button>
		</div>
	</script>

	<script type="text/html" id="detail_edit_template">
		<div class="m_tit clearfix"><b class="f18">编辑${config.beanDescription}</b></div>
		<form action="${ctx}/${simpleBeanName}/edit.do" method="post" id="addform" enctype="multipart/form-data" >
		<input type="hidden"  id="id" name="id"  value="<!=${simpleBeanName}.id!>"  />
		<div class="clearfix p_t20">
			<div class="u_info">
				<table class="u_table">
						<#list columnList as column>				
						<tr>
							<td class="t_r" >${column.dbColumnComment}：</td>
							<td><input type="text"class="all_txt" id="${column.javaPropertyName}" name="${column.javaPropertyName}"  value="<!=${simpleBeanName}.${column.javaPropertyName}!>"/></td>
						</tr>					
						</#list>					
				</table>
		</form>
			</div>
		</div>
		<div class="action_b">
			<button class="b_btn m_r20" id="enterbtn">确定</button>
			<button class="b_btn" id="backbtn">返回</button>
		</div>
	</script>

</div>

	<script type="text/javascript">

		$(function() {
			detailcon = $("#detail_con");
			tablecon = $("#table_con");
			
			//添加
			$("#addBtn").click(function() {
				changeView();
				var ht = baidu.template("detail_add_template", {});
				detailcon.html(ht);
				$("#backbtn").click(function() {
					changeView();
				});
				$("#enterbtn").click(function() {
					$("#loading").show();				
					$("#addform").ajaxSubmit(function(result){
						$("#loading").hide();
						if(result.status==1){
							search();
							alert("添加成功");
							changeView();
						}else{
							alert(result.mess);
						}
					},"json");					
				});
			});
			
			//编辑
			tablecon.delegate("[action='edit']", "click", function() {
				var id = $(this).data("id");
				common.post({
					urlFlag: "${simpleBeanName}.getById",
					id: id
				}, function(result) {
					if(result.status == 1) {
						changeView();
						var ht = baidu.template("detail_edit_template", result.data);
						detailcon.html(ht);
						$("#backbtn").click(function() {
							changeView();
						});
						$("#enterbtn").click(function() {
							$("#loading").show();						
							$("#addform").ajaxSubmit(function(result){
								$("#loading").hide();
								if(result.status==1){
									search();
									alert("修改成功");
									changeView();
								}else{
									alert(result.mess);
								}
							},"json");
						});
					} else {
						alert(result.mess);
					}
				}, "json");
			});
			
			//删除
			tablecon.delegate("[action='delete']", "click", function() {
				var id = $(this).data("id");
				if(confirm("确定删除")) {
					common.post({
						urlFlag: "${simpleBeanName}.delete",
						id: id
					}, function(result) {
						if(result.status == 1) {
							search();
							alert("删除成功");
						} else {
							alert(result.mess);
						}
					}, "json");
				}
			});
			
			//查询
			$("#searchbtn").click(function() {
				search();
			});
			
			// 页面加载完成调用查询分页
			search();
		});
	</script>
	<script type="text/javascript">
		function changeView() {
	      	 $("#detail_con").toggle();
	      	 $("#table_con").toggle();
	   	}
		function search() {
		  require(["component/table"], function(uiTable) {
			var param=$("#searchForm").serializeJson();
			common.post($.extend({
				urlFlag: '${simpleBeanName}.ajaxPage',
				pageSize: 10,
				page: 1
			}, param), function(result) {
				if(result.status == 1) {
					var table = new uiTable({
						"con": "#searchcon",
						"data": {
							"list": result.dataList
						},
						"template": "tb_template",
						"pager": {
							"con": "#tbpager",
							"data": {
								"currentPage": result.currentPage,
								"pageCount": result.pageCount,
								"rowCount": result.rowCount
							},
							template: '<a title="首页" class="page_first pre"  data-role="first">首页</a><a title="上一页" class="page_prev pre" data-role="prev" >上一页</a><span data-value="pageNum"></span><a title="下一页" class="page_next next" data-role="next" >下一页</a><a title="尾页" class="page_last next" data-role="last" >尾页</a>共<span data-target="rowCount"></span><span>条</span>'
						}
					});

					table.getPager().bind("changePage", function(event, page, hander) {
						common.post($.extend({
								urlFlag: '${simpleBeanName}.ajaxPage',
								pageSize: 10,
								page: page
							}, param),
							function(result) {
								table.render({
									"list": result.dataList
								});
								hander({
									"currentPage": result.currentPage,
									"pageCount": result.pageCount,
									"rowCount": result.rowCount
								});
							}, "json");
					});
				}
			}, "json");	
		 });
		}
	</script>	
<%@ include file="../../layout/bottom.jsp" %>